package com.example.excelzip.client;

import com.example.excelzip.domain.User;
import com.example.excelzip.mapper.UserMapper;
import com.example.excelzip.util.ExcelZip;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.util.List;

/**
 * @author 陈浩
 * @date 2021/4/14 8:56
 */
@RestController
public class UserController {

    @Autowired
    private UserMapper mapper;

    @GetMapping("get")
    public void getExcel(HttpServletResponse response) throws Exception {
        ExcelZip<User> excelZip = new ExcelZip<>(5000);

        for (int i = 0; i < 3; i++) {
            List<User> users = mapper.selectList();
            excelZip.addExcel(users, "测试");
        }

        File main;
        excelZip.getZipAndOutput(response, "测试啊啊啊啊");

        excelZip.finish();

        response.getOutputStream().flush();
    }
}
